Telegram Group & Telegram Channel
18. Program to Find GCDLCM.

import java.util.Scanner;

class GCDLCM
{
public static void main(String args[])
{
int x, y;
Scanner sc = new Scanner(System.in);

System.out.println("Enter the two numbers: ");
x = sc.nextInt();
y = sc.nextInt();

System.out.println("GCD of two numbers is : " + gcd(x, y));
System.out.println("LCM of two numbers is : " + lcm(x, y));
}

static int gcd(int x, int y)
{
int r = 0, a, b;
a = (x > y) ? x : y; // a is greater number
b = (x < y) ? x : y; // b is smaller number

r = b;
while (a % b != 0)
{
r = a % b;
a = b;
b = r;
}
return r;
}

static int lcm(int x, int y)
{
int a;
a = (x > y) ? x : y; // a is greater number
while (true)
{
if (a % x == 0 && a % y == 0)
{
return a;
}
++a;
}
}
}

@java_codings



tg-me.com/java_codings/27
Create:
Last Update:

18. Program to Find GCDLCM.

import java.util.Scanner;

class GCDLCM
{
public static void main(String args[])
{
int x, y;
Scanner sc = new Scanner(System.in);

System.out.println("Enter the two numbers: ");
x = sc.nextInt();
y = sc.nextInt();

System.out.println("GCD of two numbers is : " + gcd(x, y));
System.out.println("LCM of two numbers is : " + lcm(x, y));
}

static int gcd(int x, int y)
{
int r = 0, a, b;
a = (x > y) ? x : y; // a is greater number
b = (x < y) ? x : y; // b is smaller number

r = b;
while (a % b != 0)
{
r = a % b;
a = b;
b = r;
}
return r;
}

static int lcm(int x, int y)
{
int a;
a = (x > y) ? x : y; // a is greater number
while (true)
{
if (a % x == 0 && a % y == 0)
{
return a;
}
++a;
}
}
}

@java_codings

BY Advance Java πŸ‘¨β€πŸ’»


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/java_codings/27

View MORE
Open in Telegram


Advance Java ‍ Telegram | DID YOU KNOW?

Date: |

Dump Scam in Leaked Telegram Chat

A leaked Telegram discussion by 50 so-called crypto influencers has exposed the extraordinary steps they take in order to profit on the back off unsuspecting defi investors. According to a leaked screenshot of the chat, an elaborate plan to defraud defi investors using the worthless β€œ$Few” tokens had been hatched. $Few tokens would be airdropped to some of the influencers who in turn promoted these to unsuspecting followers on Twitter.

The global forecast for the Asian markets is murky following recent volatility, with crude oil prices providing support in what has been an otherwise tough month. The European markets were down and the U.S. bourses were mixed and flat and the Asian markets figure to split the difference.The TSE finished modestly lower on Friday following losses from the financial shares and property stocks.For the day, the index sank 15.09 points or 0.49 percent to finish at 3,061.35 after trading between 3,057.84 and 3,089.78. Volume was 1.39 billion shares worth 1.30 billion Singapore dollars. There were 285 decliners and 184 gainers.

Advance Java ‍ from ms


Telegram Advance Java πŸ‘¨β€πŸ’»
FROM USA